<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/headmeta.jsp"%>
</head>
<body>
	<div class="top">
		<div class="logo"></div>
		<div class="top-font-2">
			<a href="${ctx}/sys!goContent.action" target="mainFrame" class="font-white">首页</a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href="${ctx}/sys!logout.action" class="font-white" target="_top">退出</a>
		</div>
		<div class="top-font-1">欢迎&nbsp;${user_info.account}&nbsp;的到来！</div>
	</div>
	<div class="nav">
		<div class="space"></div>
		<div class="daohang">
			<ul id="mainMenu"></ul>
		</div>
	</div>
</body>
</html>
<script type="text/javascript">
var menuData;
var curId;
//自动调用初始化
$(document).ready(function(){
	var url="${ctx}/sys!getMenu.action";
	$.post(url, "" ,function callback(txt){
			var json = $.parseJSON(txt);
			if (json.code==0) {	
				menuData=json.info;
				createMenu();				
			}else{
				alert('获取菜单失败！');
			}
		}	
	);
	
	setInterval(checkNewMsg,20000);
});

var msgCount=-1;
function checkNewMsg(){
	var url = "${ctx}/msgOrder!getList.action?page=1&pageSize=1";
	$.post(url, "", function callback(txt) {
		var json = $.parseJSON(txt);
		if (json.code == 0) {
			var newCount=json.count;
			if(msgCount!=-1){
				if(newCount!=msgCount){
					alert('有新订单到达，请刷新消息订单查看！');
				}
			}
			msgCount=newCount;
		} 
	});
}

//创建主菜单
function createMenu(){
	var menu=document.getElementById('mainMenu');	
	var s="";
	for(var i=0;i<menuData.length;i++){
		var o=menuData[i];
		if(o.pid==''){
			s+="<li><a id='a_"+o.menuId+"' href='javascript:clickMenu(\""+o.menuId+"\");'>"+o.name+"</a></li>";
		}
	}	
	menu.innerHTML=s;
}

//点击主菜单
function clickMenu(id){
	//样式调整
	if(curId){
		$('#a_'+curId).removeClass("actived");
	}
	$('#a_'+id).addClass("actived");
	curId=id;
	//修改子菜单
	var sonMenu=new Array();
	for(var i=0;i<menuData.length;i++){
		var o=menuData[i];
		if(o.pid==id){
			sonMenu[sonMenu.length]=o;
		}
	}
	parent.leftFrame.createSonMenu(sonMenu);	
}
</script>
